import { defineStore } from 'pinia/dist/pinia'
import { listQuestionsByKeyword } from '../api/question'

export const useQuestionStore = defineStore('question', {
	state: () => {
		return {
			questionList: [],
			currentPage: 1,
			pageSize: 10,
			loading: true,
			keyword: '',
		}
	},
	getters: {},
	actions: {
		async queryQuestionsByKeyword (currentPage, pageSize, order, keyword) {
			try {
				await listQuestionsByKeyword(currentPage, pageSize, order,
					keyword).then(res => {
					if (res.code === '200') {
						this.questionList = res.data.records
						this.currentPage = res.data.current
						this.pageSize = res.data.size
						this.loading = false
					}
				})
			} catch (e) {
				return e
			}
		},
	},
})
